﻿

var manager2;
var columns =
            [
                 { display: 'Key', name: 'Key', type: 'text', hide: 1 },
                 { display: 'RoleId', name: 'RoleId', type: 'text', hide: 1 },
                { display: '姓名', name: 'Name', mintWidth: 80, width: 120 },
                { display: '性别', name: 'Gender', mintWidth: 60, width: 80 },
                { display: '组织机构', name: 'OrgName', mintWidth: 80, width: 120 }
             ];
function initligerGrid() {
    manager = null;
    manager = $("#usersGrid").ligerGrid({
        columns: columns,
        title: '用户管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '100%',
        checkbox: false,
        usePager: false,
        url: "../User/GetAllUsers?id=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) {
            $("#hidRoleId").val("").val(data.RoleId);
            /*dialogView(data.Key);*/manager2.set({ url: "../Permission/UserTreeMenuDate?roleId=" + data.RoleId + "&rand=" + Math.random() });
        }
    });
}
$(document).ready(function () {
    initligerGrid();
});

//======================================
$(function () {
    initGrid("");
    if (manager2 != null && manager2 != undefined) { manager2.windowHeight = manager2.windowHeight - 100; }
});


function initGrid(id) {
    var h = $(window).height();
    manager2 = null;
    //if (manager2 != null && manager2 != undefined) { manager2.clear(); }


    manager2 = $("#maingrid").ligerGrid({
        columns: [
                 { display: 'id', name: 'id', type: 'text', hide: 1 },
                 { display: 'isorg', name: 'isorg', type: 'text', hide: 1 },
                  { display: 'ischecked', name: 'ischecked', type: 'text', hide: 1 },
                    { display: '权限名称', name: 'text', width: 250, align: 'left' }
                ],
        title: '权限名称',
        showTitle: true,
        width:'99%',
        enabledSort: true,
        height: h-100,
        checkbox: true,
        usePager: false,
        isChecked: f_isChecked,
        //data: dataJson,
       // url: "../Permission/UserTreeMenuDate",
        tree: { columnName: 'text' }
        //onDblClickRow: function (data, rowindex, rowobj) { /*dialogView(data.Key);*/initGrid(""); }
    });

}
function f_isChecked(rowdata) {
    if (rowdata.ischecked == true)
        return true;
    return false;
}
//================================================

$(document).ready(function () {
    $("#btnCommit").unbind("click").bind("click", function () {
        var role = $("#hidRoleId").val();
        if (role != null && role != undefined && $.trim(role).length > 0) {
            getSelectTreeNode();
        }
        else {
            $.ligerDialog.success('请先双击选择用户!');
        }
    });
});





//获取选中的树结点(可多选 角色权限用)
function getSelectTreeNode() {
    var orgArray = "";
    var uiArray = "";
    if (manager2 != null && manager2 != undefined) {

        var rows = manager2.getCheckedRows();
        var str = "";
        $(rows).each(function () {
            if (this.isorg.toString() == "1") {
                orgArray += this.id + "@";
            }
            else if (this.isorg.toString() == "0") {
                uiArray += this.id + "@";
            }
        });
    }
    // return resultArray;
    $.post("../Role/SetRolePermissions", { "roleid": $("#hidRoleId").val(), "orgpermissions": orgArray.toString(), "uipermissions": uiArray.toString() }, function (data) {
        if (data != undefined && data == "ok") {
           // ajaxSubmitSuccess();
            $.ligerDialog.success('操作成功!');
        }
        else {
            $.ligerDialog.success('操作失败！');
        }
    });
}
